home *** CD-ROM | disk | FTP | other *** search
- // scrapDemo.c
- // © Copyright 1987 Consulair Corp, All Rights Reserved
- // An example of how to read information from the
- // scrap or "ClipBoard". It opens the scrap, reads its contents,
- // writes them out to a file and to the tty screen, waits for a
- // character, and exits.
-
- #include <stdio.h>
- #include <memory.h>
-
- extern char *_SF_Name;
-
- main()
- {
- FILE *file;
- char **scrapText, *scrapPtr;
- int i;
- long length, offset;
-
- scrapText = NewHandle(0);
- if ((length = GetScrap(scrapText, 'TEXT', &offset)) >= 0)
- {
- HLock(scrapText);
- scrapPtr = *scrapText;
- // Write to TTY
- printf("Got Scrap, length = %d, offset = %d\rContents: \r", length, offset);
- for (i = 0; i < length; i++) printChar(scrapPtr[i]);
- getchar();
-
- // And write to file
- if (file = fopen(".SFout", "w"))
- {
- for (i = 0; i < length; i++) fputc(scrapPtr[i], file);
- fclose(file);
- makeEditFile(_SF_Name);
- }
-
- HUnlock(scrapText);
- DisposHandle(scrapText);
- }
- else
- {
- if (length == -102) printf("\rNo Data of type TEXT in scrap");
- else printf("Error in reading scrap = %d", length);
- getchar();
- }
- }
-
-
- printChar(c)
- unsigned char c;
- {
- if (c < ' ')
- {
- switch(c)
- {
- case '\n':
- putchar('\n');
- break;
- case '\t':
- putchar(' ');
- break;
- default:
- putchar('^');
- putchar(c+'@');
- }
- }
- else
- if (c > 127)
- {
- putchar('|');
- printChar(c-128);
- }
- else putchar(c);
- }
-
-
-